<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UDP可靠性保障机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        .number-circle {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            font-size: 20px;
            flex-shrink: 0;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 1rem;
        }
        .icon-box i {
            font-size: 24px;
            color: #667eea;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        .highlight-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 700;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">UDP可靠性保障机制</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入解析UDP协议的可靠传输实现方案</p>
            <div class="flex justify-center items-center space-x-4 text-lg">
                <span><i class="fas fa-network-wired mr-2"></i>网络协议</span>
                <span class="opacity-50">|</span>
                <span><i class="fas fa-shield-alt mr-2"></i>可靠性保障</span>
                <span class="opacity-50">|</span>
                <span><i class="fas fa-code mr-2"></i>应用层实现</span>
            </div>
        </div>
    </div>

    <!-- Introduction Section -->
    <div class="max-w-6xl mx-auto px-6 py-16">
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 animate-fadeInUp">
            <div class="flex items-start space-x-4 mb-6">
                <div class="icon-box">
                    <i class="fas fa-info-circle"></i>
                </div>
                <div class="flex-1">
                    <h2 class="text-3xl font-bold mb-4 text-gray-800">概述</h2>
                    <p class="text-lg text-gray-600 leading-relaxed">
                        UDP（用户数据报协议）是一个无连接、面向数据报的协议，它不像TCP那样提供内建的可靠性保证。UDP本身不提供数据传输的可靠性，通常需要在应用层实现额外的机制来保证数据的可靠性。本文将深入探讨8种主要的UDP可靠性保障机制。
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- Visualization Section -->
    <div class="max-w-6xl mx-auto px-6 pb-8">
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
            <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">
                <i class="fas fa-project-diagram mr-3 text-purple-600"></i>UDP可靠性机制关系图
            </h2>
            <div class="mermaid">
                graph TD
                    A[UDP协议] --> B[应用层可靠性机制]
                    B --> C[数据包确认]
                    B --> D[重传机制]
                    B --> E[序列号]
                    B --> F[流量控制]
                    B --> G[校验和]
                    B --> H[超时重试]
                    B --> I[自定义协议层]
                    B --> J[数据完整性检查]
                    
                    C --> K[发送ACK消息]
                    D --> L[超时重传]
                    E --> M[数据包排序]
                    F --> N[缓存管理]
                    G --> O[错误检测]
                    H --> P[定时器管理]
                    I --> Q[协议栈实现]
                    J --> R[哈希校验]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:3px,color:#fff
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 pb-16">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
            
            <!-- 1. 数据包确认 -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-start space-x-4">
                    <div class="number-circle">1</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800 section-title">数据包确认（Acknowledgment）</h3>
                        <div class="space-y-3 text-gray-600">
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-cog text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">机制：</span>
                                    在使用UDP的应用程序中，可以设计一个确认机制，要求接收方对每个接收到的数据包发送一个确认（ACK）消息。
                                </div>
                            </div>
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-play-circle text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">工作原理：</span>
                                    发送方在发送数据包后，等待接收方的确认消息。如果在规定时间内没有收到确认，发送方会重新发送数据包。这种方式类似于TCP的确认机制，但需要应用层实现。
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 2. 重传机制 -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-start space-x-4">
                    <div class="number-circle">2</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800 section-title">重传机制（Retransmission）</h3>
                        <div class="space-y-3 text-gray-600">
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-cog text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">机制：</span>
                                    类似于TCP的重传机制，通过在应用层实现数据包重传来确保数据包的可靠传输。
                                </div>
                            </div>
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-play-circle text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">工作原理：</span>
                                    发送方在发送数据包后启动一个计时器。如果在超时时间内没有收到确认消息，发送方会重新发送该数据包。这个机制需要在应用层实现，并处理超时和重传逻辑。
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 3. 序列号 -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-start space-x-4">
                    <div class="number-circle">3</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800 section-title">序列号（Sequence Numbers）</h3>
                        <div class="space-y-3 text-gray-600">
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-cog text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">机制：</span>
                                    为每个发送的数据包分配一个唯一的序列号，以确保数据包能够按顺序到达。
                                </div>
                            </div>
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-play-circle text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">工作原理：</span>
                                    接收方根据序列号对数据包进行排序，确保接收到的数据能够按正确的顺序交给应用层。如果数据包丢失，接收方可以请求重传，或根据应用层协议来处理缺失的数据包。
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 4. 流量控制 -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-start space-x-4">
                    <div class="number-circle">4</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800 section-title">流量控制（Flow Control）</h3>
                        <div class="space-y-3 text-gray-600">
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-cog text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">机制：</span>
                                    在应用层实现流量控制机制，以避免发送方发送过多的数据包超出接收方的处理能力。
                                </div>
                            </div>
                            <div class="flex items-start space-x-2">
                                <i class="fas fa-play-circle text-purple-600 mt-1"></i>
                                <div>
                                    <span class="font-semibold text-gray-700">工作原理：</span>
                                    应用层可以设计一种机制来告知发送方当前接收方的缓存或处理能力，防止数据包的溢出和丢失。
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 5. 校验和 -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <div class="flex items-start space-x-4">
                    <div class="number-circle">5</div>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold mb-4 text-gray-800 section-title">校验和（Checksum）</h3>
                        <div class="space-y-3 text-gray-600">
                            <div class="flex items-start space-x-2">
                                <i